# 导入正则表达式的模块re,是python的内置模块
import re

s = 'i love study upup day'
pattern = r'\d\.\d+'
match = re.match(pattern, s, re.I)  # Ignore 忽略大小写
print(match)

s1 = '3.11 i love study upup day 5.1 holiday'
match1 = re.match(pattern, s1, re.I)  # Ignore 忽略大小写
print(match1)

print('起始位置：', match1.start())
print('结束位置：', match1.end())
print('匹配区间的位置：', match1.span())
print('待匹配的字符串：', match1.string)
print('匹配的数据：', match1.group())

# search 查找第一次出现
s2 = 'py3.11 i love study upup day 5.1 holiday'
match2 = re.search(pattern,s2)
match3 = re.search(pattern,s)
print(match2.group())
print(match3)

# findall 查找所有
match4 = re.findall(pattern,s2)
print(match4)

# sub 替换指定字符串
pattern1 = '黑客|爬虫|破解'
s3 = '我正在学习python爬虫技术，来破解一些VIP视频'
new_s3 = re.sub(pattern1,'***',s3)  # 遇到违禁词替换成**8
print(new_s3)

# split 分割
s4 = 'https://www.bilibili.com/video/BV1wD4y1o7AS?p=74&spm_id_from=pageDriver&vd_source=bf3be664c1161026f98725392b396aa6'
pattern2 = '[?|&]'
lst = re.split(pattern2,s4)
print(lst)